<!--
 * @Author: zhangjingyu
 * @Date: 2021-04-15 15:59:30
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2021-05-19 10:47:05
 * @FilePath: \systemCenter\src\views\ftpManage\pricingManage\pricingTask\pricingTask_engineTasks.vue
 * @Description: 定价引擎任务
-->
<template>
  <div>
    <span class="formTitle"><i class="vertical-bar"></i>{{ title }}</span>
    <el-form
      :model="searchForm"
      ref="blockRef"
      label-width="100px"
      label-position="right"
    >
      <el-row>
        <el-col :span="5" :offset="2">
          <el-form-item label="任务名称：" prop="taskName">
            <el-input
              v-model="searchForm.taskName"
              maxlength="32"
              disabled
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="5" :offset="2">
          <el-form-item label="定价编号：" prop="pricingCode">
            <el-input
              v-model="searchForm.pricingCode"
              maxlength="32"
              disabled
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="5" :offset="2">
          <el-form-item label="数据日期：" prop="dataDate">
            <el-input
              v-model="searchForm.dataDate"
              maxlength="32"
              disabled
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="5" :offset="2">
          <el-form-item label="表名称：" prop="positions">
            <el-select v-model="searchForm.pdName" style="width:100%" placeholder="请选择">
              <el-option
                v-for="item in positionOptions"
                :key="item.pdPostfix"
                :label="item.pdName"
                :value="item.pdPostfix"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="5" :offset="2">
            <el-form-item label="运行状态：" prop="status">
              <el-select
                v-model="searchForm.status"
                style="width:100%"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in statusOption"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          </el-row>
   
      <el-row class="container">
        <el-col style="margin-right:10px;" class="content-left">
          <upper-template :searchIcon="false" :configIcon="false">
            <!-- 操作按钮区 -->
            <template slot="buttonArea">
              <el-button @click="searchFunc()">查询</el-button>
              <el-button @click="toResult()">查看结果</el-button>
              <el-button @click="toExcute()">执行记录</el-button>
              <el-button @click="toSubTasks()">子任务</el-button>
              <el-button @click="goBackLast()">返回</el-button>
            </template>
          </upper-template>
        </el-col>
      </el-row>
      <el-table
        ref="blockModelTable"
        :data="blockModelData"
        style="width: 100%"
        @row-click="rowClick"
      >
      
        <el-table-column
          width="55"
          type="selection"
          
        ></el-table-column>
        <el-table-column
          prop="tableName"
          label="表名称"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="blockSize"
          label="块大小"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="dataDate"
          label="数据日期"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="startAccount"
          label="开始编号"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="endAccount"
          label="结束编号"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="nodeCode"
          label="节点编号"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="successNum"
          label="成功记录数"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="failNum"
          label="失败记录数"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="startTm"
          label="开始时间"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="endTm"
          label="结束时间"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="status"
          label="运行状态"
          :formatter="r => $getLabel(r.status, statusOption)"
          :show-overflow-tooltip="true"
        ></el-table-column>
      </el-table>
      <!-- 分页插件 -->
      <pagination
        @size-change="blockhandleSizeChange"
        @current-change="blockhandleCurrentChange"
        :current-page="searchForm.page"
        :page-size="searchForm.size"
        @refresh="searchFunc"
        :total="total"
      ></pagination>
    </el-form>
  </div>
</template>

<script>
import { getDict } from "@/api/getDict";
import { pricingTask } from "@/api/index";
import moment from "moment";
export default {
  props: {
    title: String,
    baseData: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      statusOption: [],
      positionOptions: [],
      blockModelData: [],
      searchForm: {
        page: 1,
        size: 15
      },
      total: 0
    };
  },
  created() {
    this.searchFunc();
    this.getstatus();
  },
  methods: {
    getstatus(data) {
      this.$getDict("ftp_pricing_task_status").then(res => {
        if (res.code == 200) {
          this.statusOption = res.datas;
        } else {
          this.$message.error(res.message);
        }
      });
    },
    searchFunc() {
      // let selection = this.$refs.multipleTable.selection;
      // if (selection.length != 1) {
      //   return this.$message.warning("请选择一条数据");
      // }
      let data = { pricingCode: this.baseData.pricingCode };
      //   获取表
      pricingTask
        .toBlock(data)
        .then(res => {
          if (res.code == 200) {
            this.positionOptions = res.datas.positions;
            this.searchForm.taskCode = res.datas.task.taskCode;
            this.searchForm.dataDate = moment(res.datas.task.dataDate).format(
              "yyyy-MM-DD"
            );
          }
        });
      this.searchForm.taskName = this.baseData.taskName;
      this.searchForm.pricingCode = this.baseData.pricingCode;

      let pagedata = {
        pricingCode: this.baseData.pricingCode,
        page: this.searchForm.page,
        size: this.searchForm.size
      };
      pricingTask.findAllBlock(data).then(res => {
        if (res.code == 200) {
          this.blockModelData = res.datas.rows.map(v => {
            if (v.dataDate) {
              v.dataDate = moment(v.dataDate).format("yyyy-MM-DD");
            }
            return v;
          });
          this.total = res.datas.total;
        }
      });
    },
    toResult() {
      let selection = this.$refs.blockModelTable.selection;
      if (selection.length != 1) return this.$message.warning("请选择一条数据");
      this.$emit("toResult", selection[0]);
    },
    goBackLast() {
      this.$emit("backLast", "");
    },
    toExcute() {
      this.$emit("toExcuteNotes");
    },
    toSubTasks() {
      this.$emit("toSubTasks", this.baseData);
    },
    blockhandleSizeChange(val) {
      this.searchForm.size = val;
      this.searchFunc();
    },
    blockhandleCurrentChange(val) {
      this.searchForm.page = val;
      this.searchFunc();
    },
    //点击行选中
    rowClick(row) {
      if (this.$refs.blockModelTable) {
        this.$refs.blockModelTable.clearSelection();
      }
      this.$refs.blockModelTable.toggleRowSelection(row, true);
    }
  }
};
</script>

<style lang="scss" scoped>

.formTitle {
  font-size: 14px;
  font-weight: 700;
  display: block;
  margin-bottom: 10px;
}
</style>